package com.keli.dt.model.rowmapper;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.keli.dt.algorithm.RoadReportAlgo;
import com.keli.dt.model.RoadReport;

public class RoadReportRowMapper implements RowMapper {

	@Override
	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		RoadReport rr = new RoadReport();
		rr.setDETECT_CLASS(rs.getString("DETECT_CLASS"));
		rr.setROAD_ID(rs.getBigDecimal("ROAD_ID"));
		rr.setVOLUME_NONMOTOR(rs.getBigDecimal("VOLUME_NONMOTOR"));
		rr.setVOLUME_MOTOR(rs.getBigDecimal("VOLUME_MOTOR"));
		rr.setSPEED(rs.getBigDecimal("SPEED"));
		rr.setREPORT_TIME(rs.getString("REPORT_TIME"));
		
		int nonmotorLaneSize = rs.getInt("NONMOTOR_LANE");
		BigDecimal nonmotorFlow = RoadReportAlgo.flow(rr.getVOLUME_NONMOTOR(), nonmotorLaneSize);
		rr.setFLOW_NONMOTOR(nonmotorFlow);
		int motorLaneSize = rs.getInt("MOTOR_LANE");
		BigDecimal motorFlow = RoadReportAlgo.flow(rr.getVOLUME_NONMOTOR(), motorLaneSize);
		rr.setFLOW_MOTOR(motorFlow);
		
		String collectDateTime = rs.getString("COLLEC_DATETIME");
		rr.setCOLLEC_TIME(collectDateTime);
		rr.setCOLLEC_DATETIME(collectDateTime);
		
		rr.setDENSITY(rs.getString("DENSITY"));
		
		return rr;
	}
}
